package com.csun.cmny.provider.controller.admin;


import com.csun.cmny.core.annotation.ValidateAnnotation;
import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.domain.DmcConfigureOfflineAlert;
import com.csun.cmny.provider.model.dto.configureOfflineAlert.DmcConfigureOfflineAlertDto;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.DmcConfigureOfflineAlertService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/configureOfflineAlert", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class DmcConfigureOfflineAlertController extends BaseController {

    @Resource
    private DmcConfigureOfflineAlertService dmcConfigureOfflineAlertService;

    @Resource
    private CmnyMessageSource cmnyMessageSource;
    /**
     * 新增离线报警配置
     */
    // @LogAnnotation(isSaveResponseData = true, isSaveRequestData = true)
    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "新增离线报警配置")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Wrapper addConfigureOfflineAlert(@RequestBody DmcConfigureOfflineAlert dmcConfigureOfflineAlert) {

        dmcConfigureOfflineAlert.setGroupId(getLoginAuthDto().getGroupId());


        Integer result = dmcConfigureOfflineAlertService.save(dmcConfigureOfflineAlert);

        // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

/*    *
     * 根据Id删除离线报警配置
     **/

    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "根据Id删除离线报警配置")
    @RequestMapping(value = "/deleteById/{id}", method = RequestMethod.POST)
    public Wrapper deleteConfigureOfflineAlert(@PathVariable Long id) {



        Integer result = dmcConfigureOfflineAlertService.deleteByKey(id);
        //return WrapMapper.ok();
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

/*    *
     * 修改离线报警配置
     **/


    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "修改离线报警配置")
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public Wrapper editConfigureOfflineAlert(@RequestBody DmcConfigureOfflineAlert dmcConfigureOfflineAlert) {


        Integer result = dmcConfigureOfflineAlertService.update(dmcConfigureOfflineAlert);

        // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /*分页查询离线报警*/
    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "分页查询离线报警")
    @RequestMapping(value = "/listWithPage", method = RequestMethod.POST)
    public Wrapper queryConfigureOfflineAlertListWithPage(@RequestBody DmcConfigureOfflineAlertDto configureOfflineAlertDto) {

        configureOfflineAlertDto.setGroupId(getLoginAuthDto().getGroupId());
        List<DmcConfigureOfflineAlert>dmcConfigureOfflineAlerts=dmcConfigureOfflineAlertService.queryConfigureOfflineAlertListWithPage(configureOfflineAlertDto);
        PageInfo pageInfo = new PageInfo<>(dmcConfigureOfflineAlerts);
        // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),pageInfo);
    }
}
